﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace WhittleList.Tests.Helpers
{
    public static class SignatureHelpers
    {
        public static void AssertReadyOnly(this PropertyInfo prop)
        {
            Assert.IsTrue(prop.CanRead, string.Format("Property '{0}' of class '{1}' should be able to be Read", prop.Name, prop.DeclaringType.Name));
            Assert.IsFalse(prop.CanWrite, string.Format("Property '{0}' of class '{1}' should not be able to be Written To", prop.Name, prop.DeclaringType.Name));
        }

        public static void AssertReadyWrite(this PropertyInfo prop)
        {
            Assert.IsTrue(prop.CanRead, string.Format("Property '{0}' of class '{1}' should be able to be Read", prop.Name, prop.DeclaringType.Name));
            Assert.IsTrue(prop.CanWrite, string.Format("Property '{0}' of class '{1}' should be able to be Writeable", prop.Name, prop.DeclaringType.Name));
        }

        public static void AssertInt(this PropertyInfo prop)
        {
            prop.AssertType(typeof(int));
        }

        public static void AssertString(this PropertyInfo prop)
        {
            prop.AssertType(typeof(string));
        }

        public static void AssertBinary(this PropertyInfo prop)
        {
            prop.AssertType(typeof(System.Data.Linq.Binary));
        }

        public static void AssertBool(this PropertyInfo prop)
        {
            prop.AssertType(typeof(bool));
        }

        public static void AssertDateTime(this PropertyInfo prop)
        {
            prop.AssertType(typeof(DateTime));
        }

        public static void AssertNullableDateTime(this PropertyInfo prop)
        {
            prop.AssertType(typeof(DateTime?));
        }

        private static void AssertType(this PropertyInfo prop, Type type)
        {
            Assert.AreEqual(type, prop.PropertyType);
        }
    }
}
